/*
 * Copyright (C) Michael Opitz
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA
 */
#ifndef MODEL_H
#define MODEL_H

#include <list>
#include "client.h"
#include "dom.h"
#include <boost/thread/mutex.hpp>
#include <boost/shared_ptr.hpp>

using namespace std;

/**
 * \brief This namespace contains all model-classes.
 * \author Michael Opitz
 */
namespace model {
	/** 
	 * \brief This class contains all the music-clients
	 */
	class model_class {
	public:
		model_class() {}
		/** 
		 * \brief model_class creates the model_class
		 * 
		 * \param l is a list of model-clients
		 */
		model_class(const list<model::client> &l):_clients(l) {}
		~model_class() {}

		/** 
		 * \brief get_clients returns the list of clients.
		 */
		const list<model::client>& get_clients() const 
		{
			return _clients;
		}
		/** 
		 * \brief get_clients returns the list of clients.
		 */
		list<model::client>& get_clients() { return _clients; }
		/** 
		 * \brief set_clients sets a list of clients
		 */
		void set_clients(const list<model::client> &c) {_clients = c;}

		/** 
		 * \brief get_mutex returns the mutex of the music-model
		 */
		boost::shared_ptr<boost::mutex> get_mutex();

		/** 
		 * \brief find_title finds the apriopriate title
		 * 
		 * \param file is the file of the title
		 * 
		 * \return a pointer to the title is returned. If nothing was
		 * found 0 is returned.
		 */
		model::title* find_title(const string &file);
		/** 
		 * \brief find_title finds a title
		 * 
		 * \param file is the file of the title
		 * \param c is the client from which the title come from
		 * 
		 * \return a pointer to a title is returned. If nothing was
		 * found 0 is returned.
		 */
		model::title* find_title(const string &file, model::client *c);
		/** 
		 * \brief find_client finds a client
		 * 
		 * \param name is the name of the client
		 * 
		 * \return a pointer to the client is returned. If nothing was
		 * found 0 is returned.
		 */
		model::client* find_client(const string &name);

		/** 
		 * \brief to_dom converts the music-model to a dom-structure.
		 * 
		 * \return a shared_ptr to a dom-object is returned.
		 */
		boost::shared_ptr<model::dom> to_dom() const;
	private:
		model::title* find_title(const string &, model::album *);
		model::title* find_title(const string &, model::interpreter *);
		list<model::client> _clients;
		boost::shared_ptr<boost::mutex> _mutex;
	};
}

#endif
